package com.sn.test;

import com.sn.utils.PoolingHttpClient;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.util.List;

public class NY_Item_demo {
    //南京邮电大学
    //获取文章内容(详情)
    public static void main(String[] args) {
        //使用工具类获取client连接池,获取client对象来请求网页
        PoolingHttpClient httpClient=new PoolingHttpClient();
        String uri = "http://www.njupt.edu.cn/2022/0115/c53a215263/page.htm";
        String content = httpClient.doGetHtml(uri);

        //直接使用jsoup解析content
        Document doc = Jsoup.parse(content);
        //筛选 class=Article_Source 获取文章的发布作者
        Elements article_source = doc.getElementsByClass("Article_Source");
        String author = article_source.text();
        System.out.println("====作者"+author);
        //筛选 class='Article_PublishDate' 获取发布时间
        Elements article_publishDate = doc.getElementsByClass("Article_PublishDate");
        String date = article_publishDate.text();
        System.out.println("====发布时间"+date);
        //筛选 class=wp_articlecontent 获得文章内容
        Elements newsValue = doc.getElementsByClass("wp_articlecontent");
        //将这个元素列表中所有p标签的text获取下来就是新闻的内容了
        List<String> textList = newsValue.eachText();
        StringBuffer sb=new StringBuffer();
        for (String s : textList) {
             sb.append(s);
        }
        String news= sb.toString();

        System.out.println("===============最后结果"+news);
    }
}
